#include <string>
#include <stddef.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include "csocket.h"
#include "sokoban.h"
#include "level.h"

int main(int pArgC, char* pArgs[])
{
    if(pArgC<4)
    {
        std::cerr << "usage: " << pArgs[0] << " host port boardnum" << std::endl;
        return -1;
    }

    soko::CSocket lSocket(pArgs[1],pArgs[2]);

    lSocket.WriteLine(pArgs[3]);
    
    std::string lLine;

    //read number of rows
    lSocket.ReadLine(lLine);
    int lNumRows=atoi(lLine.c_str());

    std::vector<std::string> test_lvl;

    int maxCol=0;
    for(int i=0;i<lNumRows;i++)
    {
        lSocket.ReadLine(lLine);
        test_lvl.push_back(lLine);

        if(lLine.size() > maxCol)
          maxCol = lLine.size();

        std::cout << lLine << "\n";
    }

    AI_SOKOBAN::Level test(test_lvl, lNumRows, maxCol);
	  AI_SOKOBAN::Sokoban sokoban = AI_SOKOBAN::Sokoban();

    std::string solution = sokoban.solve(test);
    std::cout << solution << std::endl;
    lSocket.WriteLine(solution);
    
    lSocket.ReadLine(lLine);
    std::cout << lLine << std::endl;

    //std::cout << "Press enter to exit... VS closing consoles ftl" << std::endl;
    //std::getchar();

	//system("PAUSE");
    return 0;
}
